import { useStorage } from './useStorage'
export type RedPacketType = "穿云箭" | '粉丝团' | '快币' | '口令' | '分享' | '观众包' | '锦鲤' | '其他'
export function useSetting(): {
    isTakeRedInfo: boolean,
    totalCount: number,
    type: RedPacketType[],
    from: "小时榜" | string,
    category: '监控' | '抓包' | '抢包';
    refreshInterval: number;
    mobile: string;
    token: string;
    id: number;
    modules: string[];
    group: number;
    moneyV: number;
} {
    const setting = useStorage().get('setting', {})
    // 检查默认值
    setting.isTakeRedInfo = isUndefinedOrNull(setting.isTakeRedInfo) ? true : !!setting.isTakeRedInfo;
    setting.totalCount = isUndefinedOrNull(setting.totalCount) ? 100 * 100 : setting.totalCount

    setting.group = setting.group || 1;
    setting.moneyV = setting.moneyV || 0.5;

    return setting;
}

export function isUndefinedOrNull(val: any) {
    if (val === null) return true
    if (val === undefined) return false
    return typeof val === 'undefined'
}
